package org.ilead.iserve.dao.impl;

import java.util.List;

import org.hibernate.LockMode;
import org.ilead.iserve.dao.IHelpInformationDAO;
import org.ilead.iserve.model.HelpInformation;
import org.ilead.iserve.model.HomePage;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class HelpInformationDAO extends HibernateDaoSupport implements
		IHelpInformationDAO {

	@Override
	public void save(HelpInformation helpInformation) {
		try {
			getHibernateTemplate().save(helpInformation);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void delete(HelpInformation helpInformation) {
		try {
			getHibernateTemplate().delete(helpInformation);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void update(HelpInformation helpInformation) {
		try {
			getHibernateTemplate().update(helpInformation);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public HelpInformation findById(Long id) {
		try {
			HelpInformation instance = (HelpInformation) getHibernateTemplate()
					.get("org.ilead.iserve.model.HelpInformation", id);
			return instance;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<HelpInformation> findByExample(HelpInformation instance) {
		try {
			List<HelpInformation> results = getHibernateTemplate()
					.findByExample(instance);
			return results;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public List<HelpInformation> findByProperty(String propertyName,
			Object value) {
		return findByProperty(propertyName, value, "");
	}

	@SuppressWarnings("unchecked")
	public List<HelpInformation> findByProperty(String propertyName, Object value, String orderBy) {
		try {
			String queryString = "from HelpInformation as model where model."
					+ propertyName + "= ? " + orderBy;
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public List<HelpInformation> findByUserId(Object userId) {
		return findByProperty(USERID, userId, "order by model.modifyTime desc");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<HelpInformation> findAll() {
		try {
			String queryString = "from HelpInformation";
		 	return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public HelpInformation merge(HelpInformation helpInformation) {
		try {
			HelpInformation result = (HelpInformation) getHibernateTemplate()
					.merge(helpInformation);
			return result;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	@Override
	public void attachDirty(HelpInformation instance) {
		try {
			getHibernateTemplate().saveOrUpdate(instance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void attachClean(HelpInformation instance) {
	        try {
	            getHibernateTemplate().lock(instance, LockMode.NONE);
	        } catch (RuntimeException re) {
	            throw re;
	        }
	}
	public static IHelpInformationDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (IHelpInformationDAO) ctx.getBean("HelpInformationDAO");
	}
	

}
